package com.doge.calcalbum.business.skin

import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.doge.calcalbum.core.base.adapters.BaseAdapter

class SkinAdapter : BaseAdapter() {
    private val dataList = mutableListOf<Skin>()

    fun submitList(data: List<Skin>) {
        dataList.clear()
        dataList.addAll(data)
        notifyDataSetChanged()
    }

    override fun getItemCount(): Int = dataList.size
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
        return when (viewType) {
            ItemType.Skin -> SkinViewHolder(parent, callback)
            else -> super.onCreateViewHolder(parent, viewType)
        }
    }

    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        val item = if (position < dataList.size) dataList[position] else null
        when (holder) {
            is SkinViewHolder -> item?.let { holder.bind(it) }
        }
    }

    override fun getItemViewType(position: Int): Int {
        if (position < 0 || position > dataList.size) return com.doge.calcalbum.core.base.adapters.ItemType.Unknown
        return ItemType.Skin
    }
}
